/**
 * 
 */
package csab.game.sprites;

import org.newdawn.slick.Animation;
import org.newdawn.slick.Color;
import org.newdawn.slick.Image;
import org.newdawn.slick.PackedSpriteSheet;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.SpriteSheet;
import org.newdawn.slick.util.Log;

import csab.core.Collidable;
import csab.core.Sprite;
import csab.game.ChaserAIController;

/**
 * Represents a slime object.
 * @author David Young
 */
public class Slime extends PlatformAISprite {
	private SpriteSheet walkingleft;
	private SpriteSheet walkingright;
	private SpriteSheet idlefwd;
	private static PackedSpriteSheet sheet;
	static {
		try {
			sheet = new PackedSpriteSheet("resource/ss/Slime.def",
					new Color(0,0,0));
		} catch (SlickException e) {
			e.printStackTrace();
		}
	}
	
	public Slime() throws SlickException
	{

		walkingleft = sheet.getSpriteSheet("slimewalkingleft");
		walkingright = sheet.getSpriteSheet("slimewalkingright");
		idlefwd = sheet.getSpriteSheet("slimeidle");
		
		Animation animlw = new Animation(walkingleft, 0, 0, 
		walkingleft.getHorizontalCount() - 1, 
		walkingleft.getVerticalCount() - 1, true, 200, true);
		animlw.setPingPong(true);
		
		Animation animrw = new Animation(walkingright, 0, 0, 
		walkingright.getHorizontalCount() - 1, 
		walkingright.getVerticalCount() - 1, true, 200, true);
		
		Animation animfwdidle = new Animation(idlefwd, 0, 0, 
				idlefwd.getHorizontalCount() - 1, 
				idlefwd.getVerticalCount() - 1, true, 200, true);
		
		Image[] img = new Image[1]; 
		img[0] = animfwdidle.getImage(0);
		Animation death = new Animation(img, 200);

		this.setWidth(animfwdidle.getImage(0).getWidth());
		this.setHeight(animfwdidle.getImage(0).getHeight());
		
		this.setMoveSpeed(Sprite.DEFAULT_MOVE_SPEED / 2);
		this.setController(new ChaserAIController(this));
		
		super.initAnims(animlw, animrw, animlw, animrw, animfwdidle, death, null, null);
	}
	/* (non-Javadoc)
	 * @see csab.core.Sprite#canAttack()
	 */
	@Override
	public boolean canAttack() {
		return false;
	}

	/* (non-Javadoc)
	 * @see csab.core.Sprite#doAttack()
	 */
	@Override
	public void doAttack() {}

	/* (non-Javadoc)
	 * @see csab.core.Entity#destroy()
	 */
	@Override
	protected void destroy() {
		try {
			this.walkingleft.destroy();
			this.walkingright.destroy();
			this.idlefwd.destroy();
		} catch (SlickException e) {
			Log.debug("Error freeing animations! " + this.getName());
		}

	}
	/* (non-Javadoc)
	 * @see csab.core.Sprite#doCollide(csab.core.Collidable)
	 */
	@Override
	public void doCollide(Collidable obj) {
		if(obj instanceof PlayerSprite)
		{
			((PlayerSprite) obj).doDamage(50);
		}
		super.doCollide(obj);
	}
	/* (non-Javadoc)
	 * @see csab.core.Sprite#prepareAttack()
	 */
	@Override
	public void prepareAttack() {
		
	}
	/* (non-Javadoc)
	 * @see csab.core.Sprite#readyToAttack()
	 */
	@Override
	public boolean readyToAttack() {return false;}

}
